home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 343_02 / gin.c < prev    next >
C/C++ Source or Header  |  1992-02-13  |  4KB  |  158 lines

  1.  
  2.         /*******************************************************
  3.         *
  4.         *       file d:\cips\gin.c
  5.         *
  6.         *       Functions: This file contains
  7.         *           get_image_name
  8.         *
  9.         *       Purpose - This function prompts the user to
  10.             *            enter the name of an image.
  11.         *
  12.         *       External Calls:
  13.         *           rstring.c - read_string
  14.         *                       clear_buffer
  15.         *
  16.         *       Modifications:
  17.         *           26 September 86 - now uses vision3.h
  18.           *               instead of vision2.h and the read_string
  19.           *               and get_integer instead of  scanf.
  20.         *           11 March 1987 - this function was
  21.           *               removed from the file ip.c and put
  22.           *               in file gin.c.
  23.         *
  24.         ******************************************************/
  25.  
  26.  
  27. #include "d:\cips\cips.h"
  28.  
  29.  
  30.  
  31.  
  32.     /*********************************************
  33.      * get_image_name(...
  34.      *
  35.      * This function reads in the desired image
  36.      * file name.
  37.      *
  38.      *********************************************/
  39.  
  40. get_image_name(name)
  41.    char name[];
  42. {
  43.    char base_name[80],
  44.          dir_name[80],
  45.           new_name[80],
  46.           response[80];
  47.     int  l;
  48.  
  49.    printf("\n\nImage name is--%s\n", name);
  50.    printf("\nDo you want to change:");
  51.    printf("\n (f) file name");
  52.    printf("\n (d) directory name");
  53.    printf("\n (n) no change");
  54.    printf("\n     _\b");
  55.    clear_buffer(response);
  56.    read_string(response);
  57.  
  58.    if((response[0] == 'F') ||
  59.       (response[0] == 'f')){
  60.       printf("\n\nEnter file name (name only no extension)");
  61.         printf("\n--");
  62.       read_string(new_name);
  63.       extract_directory_name(name, dir_name);
  64.         sprintf(name, "%s%s.tif", dir_name, new_name);
  65.    }
  66.  
  67.    if((response[0] == 'D') ||
  68.       (response[0] == 'd')){
  69.       printf("\n\nEnter directory name\n--");
  70.       read_string(dir_name);
  71.         l = strlen(dir_name);
  72.         if(dir_name[l-1] != 47){
  73.             dir_name[l]   = '/';
  74.             dir_name[l+1] = '\0';
  75.         }
  76.       printf("\n\nEnter file name (name only no extension)");
  77.         printf("\n--");
  78.       read_string(new_name);
  79.         sprintf(name, "%s%s.tif", dir_name, new_name);
  80.    }
  81.  
  82. }       /* ends get_image_name  */
  83.  
  84.  
  85.  
  86.  
  87.     /*********************************************
  88.      * extract_directory_name(...
  89.      *
  90.      * This function extracts the sub-directory
  91.      * name out of a file name.
  92.      *
  93.      *********************************************/
  94.  
  95. extract_directory_name(file_name, dir_name)
  96.     char file_name[], dir_name[];
  97. {
  98.     int i, j, k;
  99.  
  100.     i = 1;
  101.     j = 0;
  102.     k = 0;
  103.     while(i){
  104.         if(file_name[k] == 47  ||
  105.            file_name[k] == 92)     j = k;
  106.         if(file_name[k] == '\0')   i = 0;
  107.         k++;
  108.     }
  109.     j++;
  110.     strncpy(dir_name, file_name, j);
  111.     dir_name[j] = '\0';
  112.  
  113. }  /* ends extract_directory_name */
  114.  
  115.  
  116.  
  117.  
  118.  
  119.     /*********************************************
  120.      *   extract_base_image_name(...
  121.      *
  122.      *   This function looks at a full file name
  123.      *   and pulls off the sub-directory name and
  124.      *   the file extension and returns the base
  125.      *   file name.
  126.      *
  127.      *********************************************/
  128.  
  129. extract_base_file_name(file_name, base_name)
  130.    char base_name[], file_name[];
  131. {
  132.     int i, j, k;
  133.     i = 1;
  134.     j = 0;
  135.     k = 0;
  136.     while(i){
  137.         if(file_name[k] == 47  ||
  138.            file_name[k] == 92)     j = k;
  139.         if(file_name[k] == '\0')   i = 0;
  140.         k++;
  141.     }
  142.  
  143.     i = 1;
  144.     k = 0;
  145.     j++;
  146.     while(i){
  147.         if(file_name[j] == '.')
  148.            i = 0;
  149.         else
  150.            base_name[k] = file_name[j];
  151.         j++;
  152.         k++;
  153.     }
  154.     k--;
  155.     base_name[k] = '\0';
  156. printf("\nEBN> base is %s", base_name);
  157. }  /* ends extract_base_file_name */
  158.